﻿using UnityEngine;
using System.Collections;

public class DestoryByContact : MonoBehaviour {

    public GameObject explosions;
    public GameObject playerExplosions;

	public int score = 10;

	public GameManager gameController;

	void Start(){
		GameObject gameControllerObject = GameObject.Find ("GameManager");
		gameController = gameControllerObject.GetComponent<GameManager> ();
	}

    void OnTriggerEnter(Collider other)
    {
        if(other.transform.tag == "Boundary")
        {
            return;
        }

        Instantiate(explosions, transform.position, transform.rotation);
        if (other.tag == "Player")
        {
            Instantiate(playerExplosions, other.transform.position, other.transform.rotation);
        }
        Destroy(other.gameObject);
        Destroy(gameObject);

		gameController.AddScore(score);

    }
}
